package de.augsburg.chris.hausino.dao;

import java.util.List;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import de.augsburg.chris.hausino.entity.Haus;

@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class HausDAO {
	
	@PersistenceContext(unitName = "hausino")
    private EntityManager em;
	
	
	
	public List<Haus> getAll() {
		CriteriaBuilder cBuilder = em.getCriteriaBuilder();
		CriteriaQuery<Haus> hQuery = cBuilder.createQuery(Haus.class);
		Root<Haus> h = hQuery.from(Haus.class);
		hQuery.select(h);
		TypedQuery<Haus> query = em.createQuery(hQuery);
		return query.getResultList();
	}
	
	public void persist(Haus haus){
		em.merge(haus);
	}

}
